package com.siwei.mes.service.laboratory.impl;


import com.siwei.mes.common.util.*;
import com.siwei.mes.config.CompanyConfigInterceptor;
import com.siwei.mes.entity.erp.Rwdextra;
import com.siwei.mes.entity.erp.RwdextraExtend;
import com.siwei.mes.entity.erp.RwdextraInfo;
import com.siwei.mes.entity.erp.RwdextraPrintInfo;
import com.siwei.mes.entity.laboratory.ProduceHnt;
import com.siwei.mes.entity.laboratory.WtCurrent;
import com.siwei.mes.entity.mixproportion.MixProportion;
import com.siwei.mes.entity.mixproportion.MixProportionReport;
import com.siwei.mes.entity.sync.erp.ErpProject;
import com.siwei.mes.entity.system.CompanyConfig;
import com.siwei.mes.enums.SystemParamEnum;
import com.siwei.mes.mapper.erp.RwdextraExtendMapper;
import com.siwei.mes.mapper.laboratory.ContractInfoMapper;
import com.siwei.mes.mapper.laboratory.DataHntPhbMapper;
import com.siwei.mes.mapper.laboratory.KeyPropertyMapper;
import com.siwei.mes.mapper.laboratory.WTCurrentIdMapper;
import com.siwei.mes.mapper.mixProportion.MixProportionMapper;
import com.siwei.mes.mapper.syncErp.ErpProjectMapper;
import com.siwei.mes.mapper.system.CompanyConfigMapper;
import com.siwei.mes.service.laboratory.TaskListLaboratoryService;
import com.siwei.mes.service.mixProportion.impl.MixProportionServiceImpl;
import com.siwei.mes.service.system.SystemParamService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;


@Service
public class TaskListLaboratoryServiceImpl implements TaskListLaboratoryService {
    private static final Logger log = LoggerFactory.getLogger("laboratory");

    @Resource
    private MixProportionMapper mixProportionMapper;
    @Resource
    private ErpProjectMapper erpProjectMapper;
    @Resource
    private DataHntPhbMapper dataHntPhbMapper;
    @Resource
    private KeyPropertyMapper keyPropertyMapper;
    @Resource
    private RwdextraExtendMapper rwdextraExtendMapper;
    @Resource
    private ContractInfoMapper contractInfoMapper;
    @Resource
    private SystemParamService systemParamService;
    @Resource
    private MixProportionServiceImpl mixProportionService;
    @Resource
    private WTCurrentIdMapper wtCurrentIdMapper;
    @Resource
    private CompanyConfigMapper companyConfigMapper;

    @Override
    public void insertProduceHnt(Rwdextra rwdextra, String tFPhbNo, boolean isMock) {
        /**判断是否开启推送混凝土任务单到协会开关*/
        String systemParamValue = systemParamService.selectBySystemCode(SystemParamEnum.PUSH_PRODUCE_HNT, "0");
        /**如果这里是模拟同步 不管是什么直接默认1*/
        if (isMock) {
            systemParamValue = "1";
        }
        if (StringUtils.isBlank(systemParamValue) || "0".equals(systemParamValue)) {
            log.info("系统参数：【{}】暂未开启推送混凝土任务单到协会软件，不推送！", SystemParamEnum.PUSH_PRODUCE_HNT);
            return;
        }
        assertTrue(rwdextra == null, "ERP任务单信息不允许为空！");
        log.info("开始处理上传混凝土任务单到协会软件中，任务单号：【{}】，配合比：【{}】", rwdextra.getFrwdh(), tFPhbNo);

        RwdextraInfo rwdextraInfo = rwdextra.getRwdextraInfo();

        assertTrue(rwdextraInfo == null, "ERP任务单扩展信息不允许为空！");
        assertTrue(rwdextraInfo.getFHtdw() == null || rwdextraInfo.getFHtdw().isEmpty(), "施工单位不允许为空！");
        assertTrue(rwdextraInfo.getFGcmc() == null || rwdextraInfo.getFGcmc().isEmpty(), "工程名称不允许为空！");
        assertTrue(rwdextraInfo.getFRwdh() == null || rwdextraInfo.getFRwdh().isEmpty(), "任务单Id不允许为空！");

        //查询任务单详情
        RwdextraExtend rwdxq = rwdextraExtendMapper.selectByFRwdh(Integer.parseInt(rwdextraInfo.getFRwdh()));

        ProduceHnt produceHnt = new ProduceHnt();


        produceHnt.setProduceConstructUnit(NullUtils.ifNull(rwdextraInfo.getFHtdw()));//施工单位
        produceHnt.setProduceProjectName(NullUtils.ifNull(rwdextraInfo.getFGcmc()));//工程名称
        produceHnt.setProduceProjectAddress("");  //工程地址
        produceHnt.setProducePourPart(NullUtils.ifNull(rwdextraInfo.getFJzbw()));  //浇筑部位
        produceHnt.setProduceLinkMan("");
        produceHnt.setProduceLinkPhone("");

        if (StringUtils.isNotBlank(rwdextraInfo.getFTpz())) {
            String mesTpz = ConvertUtils.getMesTpz(rwdextraInfo.getFTpz());
            produceHnt.setProduceGrade(mesTpz);//砼品种
        }
        produceHnt.setProduceTakeQuan(NullUtils.ifNull(rwdextraInfo.getFJhsl()));//计划方量

        produceHnt.setProduceTaLuo(ConvertUtils.getTldUnit(rwdextraInfo.getFTld()));//生产坍落度

        produceHnt.setProduceSystemReport(0);//不管，默认为0就是
        produceHnt.setProduceIsCtrlVersion(1);//不管 传1
        produceHnt.setProduceIsViolation(0);//不管 传0
        if (rwdextraInfo.getFRwno() != null) {

            /**企业配置信息*/
            CompanyConfig companyConfig = CompanyConfigInterceptor.getCompanyConfig(1);
            if (companyConfig != null && StringUtils.isNotBlank(companyConfig.getCompanyName()) && "上海跃港混凝土有限公司".equals(companyConfig.getCompanyName())) {
                produceHnt.setProduceMemo(StringUtils.isNotBlank(rwdextraInfo.getFRwno()) ? rwdextraInfo.getFRwno() + "：" : "");
            } else {
                produceHnt.setProduceMemo("生产任务编号 (" + rwdextraInfo.getFRwno() + ")");//备注
            }
        }

        produceHnt.setProduceFinish(0);//生产完成标识
        produceHnt.setProduceDept(null);//部门
        produceHnt.setProduceCreateDate(new Date());//生产创建日期

        if (produceHnt.getProduceCreateDate() != null) {
            Random random = new Random();
            int randomSeconds = random.nextInt(11) + 10; // 生成 10 到 20 的随机数

            long timeInMillis = produceHnt.getProduceCreateDate().getTime();
            long newTimeInMillis = timeInMillis - randomSeconds * 1000;
            produceHnt.setProduceSgFbsSj(new Date(newTimeInMillis));  //生产坍落度返厂时间
        }


        //查询最大生产索引id
        Map<String, Object> maxProduceIndexId = dataHntPhbMapper.findMaxProduceIndexId();

        if (maxProduceIndexId == null || maxProduceIndexId.get("Produce_IndexId") == null) {
            log.error("查询最大值 生产任务Produce_IndexId为空！");
            throw new RuntimeException("查询最大值 生产任务Produce_IndexId为空！");
        }

        String Produce_IndexId = maxProduceIndexId.get("Produce_IndexId").toString();

        //当前年份后两位值
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        String yearLastTwoDigits = String.valueOf(year);


        //默认最大值 +1
        String produceIndexId = null;

        //入场编号生成规则（Import_ID）
        //年份+六位自增序号(2024001002)

        //判断最大值是否是当前年份
        if (Produce_IndexId.substring(0, 4).equals(yearLastTwoDigits)) {
            //默认最大值 +1
            produceIndexId = String.valueOf(Integer.parseInt(Produce_IndexId) + 1);
        } else {
            produceIndexId = yearLastTwoDigits + "000001";
        }

        produceHnt.setProduceIndexId(produceIndexId);//生产索引 ID

        produceHnt.setUploadFlag(UploadFlagUtils.CtoGB_Num(produceIndexId, "z", new Date(), null));//上传标识   生产索引 ID + z + new Date


        String phbNo = null;
        //配合比不为空
        if (StringUtils.isNotBlank(tFPhbNo)) {
            phbNo = tFPhbNo;
        } else if (StringUtils.isNotBlank(rwdextra.getPhbshow())) {
            phbNo = rwdextra.getPhbshow();
        }
        log.info("开始处理上传混凝土任务单到协会软件中,配合比编号:{}", phbNo);

        if (StringUtils.isNotBlank(phbNo)) {
            produceHnt.setProducePhbBH(phbNo);//基准配比编号
            String ksdj = rwdextraInfo.getKsdj();


            /**这里需要拼接对应抗渗等级*/
/*
            if (StringUtils.isNotBlank(ksdj)) {
                produceHnt.setProducePhbBH(phbNo + ksdj);
                //查询协会是否有新增的配合比编号
                Map<String, Object> data_hntphbByBh = dataHntPhbMapper.findDATA_HNTPHBByBh(phbNo + ksdj);
                if (data_hntphbByBh == null) {
                    //新增
                    //查询品控配合比信息
                    List<MixProportion> list = mixProportionMapper.getList(new MixProportion().setProportionPhb(phbNo));
                    if (list != null && !list.isEmpty() && list.size() != 0) {
                        MixProportion newMixProportion = list.get(0);
                        newMixProportion.setProportionPhb(phbNo + ksdj);
                        newMixProportion.setProportionKsdj(ksdj);
                        //如果协会没有这个配比 则新增 组装配比+抗渗等级 成为一个信配比
                        mixProportionService.uploadAssociation(newMixProportion);
                    }
                }

            } else {
                produceHnt.setProducePhbBH(phbNo);//基准配比编号
            }*/
            //查询配合比信息
/*            List<MixProportion> list = mixProportionMapper.getList(new MixProportion().setProportionPhb(phbNo));
            if (list != null && !list.isEmpty() && list.size() != 0) {
                //配合比信息
                MixProportion mixProportion = list.get(0);

                if (StringUtils.isNotBlank(ksdj)) {
                    produceHnt.setProduceKangShen(ksdj);//抗渗等级
                    produceHnt.setProduceKsCheck(1);
                } else {
                    produceHnt.setProduceKangShen(NullUtils.ifNull(mixProportion.getProportionKsdj(), "---"));//抗渗等级
                    produceHnt.setProduceKsCheck(0);//待定
                }
                produceHnt.setProduceKangZhe(NullUtils.ifNull(mixProportion.getProportionKzqd(), "---"));//抗折强度

                //原材料报告信息 json 转对象
                MixProportionReport mixProportionReport = mixProportion.getProportionMaterial().toJavaObject(MixProportionReport.class);
                MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
                MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
                MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
                MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
                MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
                MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
                MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();

                produceHnt.setReportIDC(NullUtils.ifNull(sn.getXhbgbh(), "---"));//水泥报告编号
                produceHnt.setReportIDF(NullUtils.ifNull(fmh.getXhbgbh(), "---"));//粉煤灰报告编号
                produceHnt.setReportIDZ(NullUtils.ifNull(kzf.getXhbgbh(), "---"));//矿粉报告编号
                produceHnt.setReportIDS(NullUtils.ifNull(xgl.getXhbgbh(), "---"));//细骨料报告编号
                produceHnt.setReportIDG(NullUtils.ifNull(cgl.getXhbgbh(), "---"));//粗骨料报告编号
                produceHnt.setReportIDAd(NullUtils.ifNull(wjj1.getXhbgbh(), "---"));//外加剂报告编号
                produceHnt.setReportIDAd2(NullUtils.ifNull(wjj2.getXhbgbh(), "---"));//外加剂 2报告编号

                produceHnt.setHeadStreamC(NullUtils.ifNull(sn.getCj()));//水泥厂家
                produceHnt.setHeadStreamS(NullUtils.ifNull(xgl.getCj()));//细骨料厂家
                produceHnt.setHeadStreamG(NullUtils.ifNull(cgl.getCj()));//粗骨料厂家
                produceHnt.setHeadStreamF(NullUtils.ifNull(fmh.getCj()));//粉煤灰厂家
                produceHnt.setHeadStreamZ(NullUtils.ifNull(kzf.getCj()));//矿粉厂家
                produceHnt.setHeadStreamAd(NullUtils.ifNull(wjj1.getCj()));//外加剂厂家
                produceHnt.setHeadStreamAd2(NullUtils.ifNull(wjj2.getCj()));//外加剂 2厂家
                produceHnt.setHeadStreamOther("--");//其他厂家

                produceHnt.setBazC(NullUtils.ifNull(sn.getCertificateNo(), "--"));//水泥备案证
                produceHnt.setBazS(NullUtils.ifNull(xgl.getCertificateNo(), "--"));//细骨料备案证
                produceHnt.setBazG(NullUtils.ifNull(cgl.getCertificateNo(), "--"));//粗骨料备案证
                produceHnt.setBazF(NullUtils.ifNull(fmh.getCertificateNo(), "--"));//粉煤灰备案证
                produceHnt.setBazZ(NullUtils.ifNull(kzf.getCertificateNo(), "--"));//矿粉备案证
                produceHnt.setBazAd(NullUtils.ifNull(wjj1.getCertificateNo(), "--"));//外加剂备案证
                produceHnt.setBazAd2(NullUtils.ifNull(wjj2.getCertificateNo(), "--"));//外加剂2备案证
            }*/

            if (rwdxq != null) {
                RwdextraPrintInfo rwdextraPrintInfo = JsonUtils.getObject(rwdxq.getPrintJson(), RwdextraPrintInfo.class);
                if (rwdextraPrintInfo != null) {
                    MixProportion mixProportion = rwdextraPrintInfo.getMixProportionInfo();
                    if (mixProportion != null) {
                        if (StringUtils.isNotBlank(ksdj)) {
                            produceHnt.setProduceKangShen(ksdj);//抗渗等级
                            produceHnt.setProduceKsCheck(1);
                        } else {
                            produceHnt.setProduceKangShen(NullUtils.ifNull(mixProportion.getProportionKsdj(), "---"));//抗渗等级
                            produceHnt.setProduceKsCheck(0);//待定
                        }
                        produceHnt.setProduceKangZhe(NullUtils.ifNull(mixProportion.getProportionKzqd(), "---"));//抗折强度

                        //原材料报告信息 json 转对象
                        MixProportionReport mixProportionReport = mixProportion.getProportionMaterial().toJavaObject(MixProportionReport.class);
                        MixProportionReport.BgxxInfo sn = mixProportionReport.getSn();
                        MixProportionReport.BgxxInfo fmh = mixProportionReport.getFmh();
                        MixProportionReport.BgxxInfo kzf = mixProportionReport.getKzf();
                        MixProportionReport.BgxxInfo cgl = mixProportionReport.getCgl();
                        MixProportionReport.BgxxInfo xgl = mixProportionReport.getXgl();
                        MixProportionReport.BgxxInfo wjj1 = mixProportionReport.getWjj1();
                        MixProportionReport.BgxxInfo wjj2 = mixProportionReport.getWjj2();

                        produceHnt.setReportIDC(NullUtils.ifNull(sn.getXhbgbh(), "---"));//水泥报告编号
                        produceHnt.setReportIDF(NullUtils.ifNull(fmh.getXhbgbh(), "---"));//粉煤灰报告编号
                        produceHnt.setReportIDZ(NullUtils.ifNull(kzf.getXhbgbh(), "---"));//矿粉报告编号
                        produceHnt.setReportIDS(NullUtils.ifNull(xgl.getXhbgbh(), "---"));//细骨料报告编号
                        produceHnt.setReportIDG(NullUtils.ifNull(cgl.getXhbgbh(), "---"));//粗骨料报告编号
                        produceHnt.setReportIDAd(NullUtils.ifNull(wjj1.getXhbgbh(), "---"));//外加剂报告编号
                        produceHnt.setReportIDAd2(NullUtils.ifNull(wjj2.getXhbgbh(), "---"));//外加剂 2报告编号

                        produceHnt.setHeadStreamC(NullUtils.ifNull(sn.getCj()));//水泥厂家
                        produceHnt.setHeadStreamS(NullUtils.ifNull(xgl.getCj()));//细骨料厂家
                        produceHnt.setHeadStreamG(NullUtils.ifNull(cgl.getCj()));//粗骨料厂家
                        produceHnt.setHeadStreamF(NullUtils.ifNull(fmh.getCj()));//粉煤灰厂家
                        produceHnt.setHeadStreamZ(NullUtils.ifNull(kzf.getCj()));//矿粉厂家
                        produceHnt.setHeadStreamAd(NullUtils.ifNull(wjj1.getCj()));//外加剂厂家
                        produceHnt.setHeadStreamAd2(NullUtils.ifNull(wjj2.getCj()));//外加剂 2厂家
                        produceHnt.setHeadStreamOther("--");//其他厂家

                        produceHnt.setBazC(NullUtils.ifNull(sn.getCertificateNo(), "--"));//水泥备案证
                        produceHnt.setBazS(NullUtils.ifNull(xgl.getCertificateNo(), "--"));//细骨料备案证
                        produceHnt.setBazG(NullUtils.ifNull(cgl.getCertificateNo(), "--"));//粗骨料备案证
                        produceHnt.setBazF(NullUtils.ifNull(fmh.getCertificateNo(), "--"));//粉煤灰备案证
                        produceHnt.setBazZ(NullUtils.ifNull(kzf.getCertificateNo(), "--"));//矿粉备案证
                        produceHnt.setBazAd(NullUtils.ifNull(wjj1.getCertificateNo(), "--"));//外加剂备案证
                        produceHnt.setBazAd2(NullUtils.ifNull(wjj2.getCertificateNo(), "--"));//外加剂2备案证
                    }
                }
            }

        }

        if (rwdextraInfo.getFHtbh() != null && !rwdextraInfo.getFHtbh().isEmpty()) {
            //查询合同信息
            List<ErpProject> list = erpProjectMapper.getList(new ErpProject().setContractNo(rwdextraInfo.getFHtbh()));
            if (list != null && !list.isEmpty() && list.size() != 0) {
                ErpProject erpProject = list.get(0);

                if (erpProject.getLaboratoryId() != null && !erpProject.getLaboratoryId().isEmpty()) {
                    produceHnt.setProduceContractId(erpProject.getLaboratoryId());//合同 ID

                    Map<String, Object> map = contractInfoMapper.selectContractData(erpProject.getLaboratoryId());
                    if (map != null && map.get("Cust_Id") != null) {
                        produceHnt.setProduceCustId(map.get("Cust_Id").toString());//生产客户 ID
                    }
                }


                if (erpProject.getBjbh() != null && !erpProject.getBjbh().isEmpty()) {
                    produceHnt.setProduceContractBjbh(erpProject.getBjbh());//合同报建编号
                } else {
                    produceHnt.setProduceContractBjbh("---");//合同报建编号
                }

                produceHnt.setProduceContractJsdw(erpProject.getJsdw());//生产合同建设单位
                produceHnt.setProduceContractJldw(erpProject.getJldw());//合同监理单位
            } else {
                produceHnt.setProduceContractBjbh("---");//合同报建编号
            }
        } else {
            produceHnt.setProduceContractBjbh("---");//合同报建编号
        }

        //查询配置表
        List<CompanyConfig> companyConfiglist = companyConfigMapper.getList(new CompanyConfig());

        if (companyConfiglist != null && !companyConfiglist.isEmpty()) {
            produceHnt.setProduceMemberCode(companyConfiglist.get(0).getCompanyAssociationMember());
        }

        produceHnt.setProduceKzCheck(0);

        if (StringUtils.isNotBlank(rwdextraInfo.getFTpz())) {
            String mesTpzToKz = ConvertUtils.getMesTpzToKz(rwdextraInfo.getFTpz());
            if (StringUtils.isNotBlank(mesTpzToKz)) {
                produceHnt.setProduceKzCheck(1); //抗折
            }
        }


        produceHnt.setProduceCheckFlag(0);//待定值


        if (StringUtils.isNotBlank(rwdextraInfo.getFTbj())) {
            String fTbj = rwdextraInfo.getFTbj();
            String ftbjValue = RwdextraInfo.getFtbjValue(fTbj, 3);
            if (StringUtils.isNotBlank(ftbjValue)) {
                produceHnt.setProduceKsCheck(1);
            }
        }

        if (rwdextraInfo.getFJzfs() != null && "泵送".equals(rwdextraInfo.getFJzfs())) {
            produceHnt.setProduceSgBs(1);  //生产坍落度标识
            produceHnt.setProduceSgBsBj(rwdextraInfo.getFJhsl());  //生产坍落度标识值
        } else {
            produceHnt.setProduceSgBs(0);  //生产坍落度标识
        }

        produceHnt.setProduceSgFbs(0);  //生产坍落度返厂标识
        produceHnt.setProduceStartProduceDate(rwdextra.getPlantime());//开始生产日期
        produceHnt.setProducePlanEndDate(rwdextra.getPlantime());//计划结束日期

        //代表第一车生产完成  说明是已发料
        if (rwdxq != null && rwdxq.getIsHasItemorder() != null && "1".equals(rwdxq.getIsHasItemorder().toString())) {
            produceHnt.setProduceStartIssue(1);//开始发货标识
            produceHnt.setProduceRealIssueDate(rwdextra.getCurrentpctime());//实际发货日期
        } else {
            produceHnt.setProduceStartIssue(0);//开始发货标识
            produceHnt.setProduceRealIssueDate(rwdextra.getPlantime());//实际发货日期
        }


        //任务单扩展表
        RwdextraExtend rwdextraExtend = rwdextra.getRwdextraExtend();

        String newId = keyPropertyMapper.getNewId();

        //根据关联判断是否新增还是修改协会任务单信息
        if (rwdextraExtend != null) {
            //协会任务单id不为空
            if (rwdextraExtend.getProduceId() != null && !rwdextraExtend.getProduceId().isEmpty()) {
                ProduceHnt produce_hnt = dataHntPhbMapper.findProduce_Hnt(rwdextraExtend.getProduceId());
                if (produce_hnt == null) {
                    produceHnt.setProduceId(newId);
                    dataHntPhbMapper.addProduce_Hnt(produceHnt);
                } else {
                    produceHnt.setProduceId(rwdextraExtend.getProduceId());

                    //修改 用原来的indexId
                    if (produce_hnt.getProduceIndexId() != null) {
                        produceHnt.setProduceIndexId(produce_hnt.getProduceIndexId().toString());//生产索引 ID
                    }

                    if (produce_hnt.getProduceCreateDate() != null) {
                        String produce_createDate = produce_hnt.getProduceCreateDate().toString();
                        Date date = DateHelper.parseDateTime(DateHelper.getDefaultDateTimeFormat(), DateHelper.getDefaultLocal(), produce_createDate);
                        produceHnt.setProduceCreateDate(date);//生产创建日期
                    }

                    if (produce_hnt.getProduceSgFbsSj() != null) {
                        String produce_createDate = produce_hnt.getProduceSgFbsSj().toString();
                        Date date = DateHelper.parseDateTime(DateHelper.getDefaultDateTimeFormat(), DateHelper.getDefaultLocal(), produce_createDate);
                        produceHnt.setProduceSgFbsSj(date);//生产创建日期
                    }

                    if (produce_hnt.getProduceStartIssue() != null && "1".equals(produce_hnt.getProduceStartIssue().toString())) {
                        produceHnt.setProduceStartIssue(1);//开始发货标识

                        if (produce_hnt.getProduceRealIssueDate() != null) {
                            String produce_createDate = produce_hnt.getProduceRealIssueDate().toString();
                            Date date = DateHelper.parseDateTime(DateHelper.getDefaultDateTimeFormat(), DateHelper.getDefaultLocal(), produce_createDate);
                            produceHnt.setProduceRealIssueDate(date);//生产创建日期
                        }

                    }

                    dataHntPhbMapper.updateProduce_Hnt(produceHnt);
                }

                //新增关联关系
                rwdextraExtend.setStatus("1").setReason("").setUpdateTime(new Date());
                rwdextraExtendMapper.updateByPrimaryKeySelective(rwdextraExtend);

            } else {
                //协会任务单id 为空 则新增协会
                produceHnt.setProduceId(newId);
                dataHntPhbMapper.addProduce_Hnt(produceHnt);

                //新增关联关系
                rwdextraExtend.setProduceId(newId).setProduceIndexId(produceIndexId).setStatus("1").setReason("").setUpdateTime(new Date());
                rwdextraExtendMapper.updateByPrimaryKeySelective(rwdextraExtend);

                WtCurrent wtCurrentId = wtCurrentIdMapper.findWTCurrentId(yearLastTwoDigits);
                if (wtCurrentId == null) {
                    //新增WT_CurrentId表
                    WtCurrent wtCurrent = new WtCurrent().setYearStr(yearLastTwoDigits).setCurrentProduceId(produceHnt.getProduceIndexId())
                            .setCurrentConsignId("0000000001").setCurrentSampleId("0000000001").setCurrentImportId("0000000001");
                    wtCurrentIdMapper.addWtCurrentId(wtCurrent);
                } else {
                    //修改WT_CurrentId表
                    WtCurrent wtCurrent = new WtCurrent().setYearStr(yearLastTwoDigits).setCurrentProduceId(produceHnt.getProduceIndexId());
                    wtCurrentIdMapper.updateWtCurrentIdCurrentProduceId(wtCurrent);
                }
            }

        }


    }

    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        String yearLastTwoDigits = String.valueOf(year);
        System.out.println(yearLastTwoDigits);
    }

}